from PySide2.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout
from PySide2.QtGui import QIcon
from PySide2.QtCore import Qt, QSize
from qfluentwidgets import ElevatedCardWidget, IconWidget, InfoBarIcon, BodyLabel


class TextCard(ElevatedCardWidget):
    def __init__(self, text, icon, parent=None):
        super().__init__(parent)
        self.layout = QHBoxLayout(self)
        self.setLayout(self.layout)
        self.icon = icon
        self.label = BodyLabel(text, self)
        self.layout.addWidget(self.icon)
        self.layout.addWidget(self.label)
        self.setFixedHeight( 50)


class TimelineWidget(QWidget):
    def __init__(self, parent=None):
        super(TimelineWidget, self).__init__(parent)
        self.vboxLayout = QVBoxLayout(self)
        self.vboxLayout.setContentsMargins(50, 0, 50, 0)
        self.add_update('2025/03/04', ['重构UI界面', '补充部分贴图资源和其他职业的装备数据'])
        self.add_update('2025/03/01', ['配装工具补充新版本数据，包括新装备、神兵武器等'])
        self.add_update('2025/02/07', ['初步实现配装工具'])

    def add_update(self, date_string, texts):
        widget = QWidget(self)
        layout = QHBoxLayout(widget)
        label = BodyLabel(date_string, self)
        label.setStyleSheet("font: 20pt 'Segoe UI SemiBold', 'Microsoft YaHei SemiBold'; color:white; padding-left: 0px")
        layout.addWidget(label)
        self.layout().addWidget(widget)
        for text in texts:
            icon = IconWidget(InfoBarIcon.SUCCESS, self)
            icon.setFixedSize(20, 20)
            text_card = TextCard(text, icon)
            self.layout().addWidget(text_card)